<?php 
/**
 * 获取用户粉丝联和用户关注的账号
 * @author [cnsecer] <[root@cnsecer.com]>
 */
namespace Home\Controller;
use Think\Controller;
class FriendsController extends CommonController{
    //我关注的所有用户列表
    public function friends(){

        $cur=0;
        if(I('p'))  $cur = I('p');
        $c   = $this->c;   
        $uid = $this->uid; //微博用户UID
        $f = $c->friends_by_id( $uid, $cursor = $cur, $count = 50 );
        $count = (string)floor($f['total_number']/50)+1; //分页总数
        $page  = new \Think\Page($count,1);// 一次一个分页
        $this->page = $page->show(); //页码
        $this->friends = $f;
        $this->display();
    }
    //获取共同关注用户列表
    public function bilateral(){
        $cur = 1;
        if(I('p'))  $cur = I('p');
        $c   = $this->c;   
        $uid = $this->uid; //微博用户UID
        $b = $c->bilateral( $uid,  $page = $cur, $count = 50,$sort = 0  );
        $count = (string)floor($b['total_number']/50)+1; //分页总数
        $this->friends = $b;
        $page  = new \Think\Page($count,1);// 一次一个分页
        $this->page = $page->show(); //页码
        $this->display(); 
    }
    //获取用户粉丝列表
    public function followers(){
        $cur=0;
        $cou=50;
        if(I('p'))  $cur = I('p');

        $c   = $this->c;   
        $uid = $this->uid; //微博用户UID
        $f = $c->followers_by_id( $uid, $cursor = $cur, $count = 50 );
        $count = (string)floor($f['total_number']/50)+1; //分页总数   
        $page  = new \Think\Page($count,1);// 一次一个分页
        $this->page = $page->show(); //页码     
        $this->friends = $f;
        $this->display();          
    }
	//取消关注某个用户 
    public function destroy(){
        $c  = $this->c;  
        $n=0; //默认取消关注0人
        foreach(I() as $vs ){
            if(is_array($vs)){ //如果POST过来的是数组....
                foreach($vs as $v){
                    $result = $c->unfollow_by_id( $v ); 
                    if(isset($result['id'])){
                        $n++;
                    }  
                }
            }else{
                $result = $c->unfollow_by_id( $vs ); 
                if(isset($result['id'])){
                    $n = 1;
                }  
            }
        }
        $vo['status'] = 1;
        $vo['info'] = "成功取消关注".$n."人";
       // $this->success("成功取消关注".$n."人");
       $this->ajaxReturn($vo,'json');
    }
}



 ?>